<?php
/**
 * Created by JetBrains PhpStorm.
 * User: zhouyang
 * Date: 13-9-06
 * Time: 下午22:31
 * To change this template use File | Settings | File Templates.
 */
class AdTimesDB  extends DBReader{
    //获取对应推广的排期表
    public function getTimesByAdId($ad_id){
        $where = ' 1=1 and ad_id = '.$ad_id;
        $bindarr = array();

        $sql = 'select ad_time_id, ad_id, start_time, end_time from ad_times where '. $where .' order by ad_time_id desc';

        $ret = $this->db()->getAll($sql,$bindarr);

         return $ret;
    }

    //添加推广排期信息
    public function addAdTimes($ad_id, $start_time,$end_time){
        $sql = "insert into ad_times(ad_id, start_time, end_time) values(:ad_id, :start_time, :end_time)";

        $bindarr = array(
            'ad_id'=>$ad_id,
            'start_time'=>$start_time,
            'end_time'=>$end_time
        );
        $this->db()->execute($sql,$bindarr);
        return $this->db()->lastInsertId();
    }

    //删除推广排期信息
    public function delAdTimes($ad_time_id){

        $sql = "delete from ad_times where ad_time_id = :ad_time_id";

        $bindarr = array(
            'ad_time_id'=>$ad_time_id,
        );
        $rs = $this->db()->execute($sql,$bindarr);

        return $rs->rowCount();
    }

    //根据推广编号删除推广排期信息
    public function delAdTimesByAdId($ad_id){

        $sql = "delete from ad_times where ad_id = :ad_id";

        $bindarr = array(
            'ad_id'=>$ad_id,
        );
        $rs = $this->db()->execute($sql,$bindarr);

        return $rs->rowCount();
    }

    //修改推广排期信息
    public function updateAdTimes($ad_time_id, $start_time, $end_time){
        $sql = "update ad_times set start_time = :start_time,end_time = :end_time where ad_time_id = :ad_time_id";
        $bindarr = array(
            'ad_time_id' => $ad_time_id,
            'start_time'=>$start_time,
            'end_time'=>$end_time
        );
        return $this->db()->execute($sql,$bindarr);
    }
}